<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" th:href="@{/css/bootstrap.min.css}" type="text/css" />
    <script th:src="@{/js/jquery-3.3.1.min.js}"></script>
</head>
<body>
<input type="file" class="hidden" id="file1">
<button class="btn btn-info" type="button" value="选择文件" onclick="$('#file1').click()">选择文件</button>
<input type="button" class="btn btn-success" onclick="importExcle()" value="导入">
<div><textarea id="data" cols="50" rows="10" style="margin: 30px 0px 0px; height: 360px; width: 530px;"></textarea></div>
</body>
<script type="text/javascript">
    function importExcle() {
        if($("#file1").val().length <=0){
            alert("请选择文件");
            return false;
        }else{
            var filepath = $("#file1").val();
            var extStart = filepath.lastIndexOf(".");
            var ext = filepath.substring(extStart,filepath.length).toUpperCase();
            if (ext != ".XLSX" && ext != ".XLS" && ext != ".XLSM") {
                alert("请上传excel格式文档");
                return false;
            }
        }
        //获取到上传的文件信息
        var data =document.getElementById("file1").files[0];
        var fromData = new FormData();

        if(data != null){
            fromData.append("file",data);
            $.ajax({
                type: "post",
                url:   "../student/import",
                data: fromData,
                dataType: "json",
                contentType: false,
                processData: false,
                success: function (data) {
                    $("#data").html(JSON.stringify(data,null,"\t"));
                }
            });
        }
    }
</script>
</html>